package edu.kit.aifb.ldstream.learner.util;

import java.util.Comparator;

public class DescendingComparator implements Comparator<String>{

	@Override
	public int compare(String o1, String o2) {
		
		if(o1.length() == o2.length()){
			int index = o1.length() - 1;
			// checking equality in reverse order
			while(index != -1){
				if(o1.charAt(index) == o2.charAt(index)){
					index--;
				}else{
					//found different char
					return o1.charAt(index) - o2.charAt(index);
				}
			}
			//strings are equal
			return 0;
		}else if(o1.length() < o2.length()){
			return -1;
		}else{
			return 1;
		}
		
		/*
		StringBuilder sb1 = new StringBuilder(o1);
		StringBuilder sb2 = new StringBuilder(o2);
		sb1.reverse();
		sb2.reverse();
		return sb1.toString().compareTo(sb2.toString());
		*/
	}
}
